<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

include_once (APPPATH . '/helpers/assets/url.php');
include_once (APPPATH . '/helpers/assets/upload.php');
include_once (APPPATH . '/helpers/assets/shop.php');

function getOption($key)
{
    $ci = &get_instance();
    $ci->load->model('repo/options_model', 'options_model');
    return $ci->options_model->get($key);
}

function fdate_format($date, $format = "Y-m-d")
{
    $date = new DateTime($date);
    return $date->format($format);
}

function get_current_date($format = "Y-m-d H:i:s")
{
    $date = new DateTime();
    return $date->format($format);
}

function assets($path, $is_common = false, $theme_path = null)
{
    $theme = '';
    if ($is_common) {
        $theme = 'common';
    } else {
        if ($theme_path != null) {
            $theme = $theme_path;
        } else {
            $theme = config_item('front_theme');
        }
    }
    return base_url('assets/' . $theme . '/' . $path);
}

function currency_format($price)
{
    $val = number_format($price, 0, null, '.') . '<sup>đ</sup>';
    return $val;
}

function get_template_item($item)
{
    $ci = &get_instance();
    $theme = config_item('front_theme');
    $ci->load->view('frontend/' . $theme . '/layout/' . $item . '.html.php');
}

function get_front_theme_item($item, $data = array())
{
    $ci = &get_instance();
    $theme = config_item('front_theme');
    $ci->load->view('frontend/' . $theme . '/' . $item . '.html.php', $data);
}

function image_exist($name)
{
    $pattr = FCPATH . UPLOAD_FOLDER_URL . $name;
    return file_exists($pattr);
}

function get_attachment($path, $theme = null)
{
    if ($theme != null) {
        return FCPATH . 'assets/' . $theme . '/' . $path;
    }
    return FCPATH . 'uploads/public/' . $path;
}

?>